package com.ttg.common.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * 统一使用base64版本，方便维护
 */
public class Base64Util {


    public static String encodeData(byte[] origData) {
        return new String(encodeDataByte(origData)).replace("\r\n", "").replace("\n", "");
    }

    public static String encodeData(String data) {
        return new String(encodeDataByte(data.getBytes(StandardCharsets.UTF_8))).replace("\r\n", "").replace("\n", "");
    }

    public static byte[] encodeDataByte(String data) {
        return encodeDataByte(data.getBytes(StandardCharsets.UTF_8));
    }


    public static byte[] decodeData(String base64Data) {
        return decodeDataByte(base64Data.getBytes(StandardCharsets.UTF_8));
    }

    public static String decodeDataStr(String base64Data) {
        return new String(decodeDataByte(base64Data.getBytes(StandardCharsets.UTF_8)));
    }

    public static String decodeDataStr(byte[] origData) {
        return new String(decodeDataByte(origData));
    }


    public static byte[] encodeDataByte(byte[] origData) {
        return Base64.getEncoder().encode(origData);
    }


    public static byte[] decodeDataByte(byte[] origData) {
        return Base64.getDecoder().decode(origData);
    }
}
